package com.taxicall.client;

import java.util.ArrayList;
import com.taxicall.entities.TaxiLocation;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;


public class StartPointSelection extends ListActivity {
	
	private static ArrayList<TaxiLocation> points;

	private String serverip;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		points = (ArrayList<TaxiLocation>) getIntent().getExtras().getSerializable("TaxiLocations");
		TaxiLocation[] tls = new TaxiLocation[points.size()];
		points.toArray(tls);
		MyArrayAdapter adapter = new MyArrayAdapter(this, tls);
		setListAdapter(adapter);
		setContentView(R.layout.activity_start_point_selection);
	}
	
	protected void onListItemClick(ListView l, View v, int position, long id) {
		final TaxiLocation tl = (TaxiLocation) getListAdapter().getItem(position);
		AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
		myAlertDialog.setTitle("Starting point");
		myAlertDialog.setMessage("You really want to select "+tl.getName()+" as your starting point?");
		myAlertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
			
			public void onClick(DialogInterface dialog, int which) {
				
				Intent intent = new Intent(getApplicationContext(), DestinationSelection.class);
				intent.putExtra("startingLocation", tl);
				intent.putExtra("serverip", getIntent().getStringExtra("serverip"));
				startActivity(intent);
			}
		});
		myAlertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
			
			public void onClick(DialogInterface dialog, int which) {}
		});
		myAlertDialog.show();
	}
}
